import Mock from 'mockjs'; // 引入mockjs
import Qs from 'qs';
const Random = Mock.Random;  // Mock.Random 是一个工具类，用于生成各种随机数据
const VITE_API_URL = import.meta.env.VITE_APP_BASE_API;


// 接口/mall4cloud_product/ua/category/category_list
Mock.mock(
  new RegExp(VITE_API_URL + '/mall4cloud_product/ua/category/category_list' + '.*'),
  'get',
  (options?: object): any => {
    let tempObj = Mock.mock({
      "categoryList|1-10": [
        {
          "categoryId|+1": [
            Random.guid(),
            Random.guid(),
            Random.guid(),
          ],
          'name|+1':[
            Random.ctitle(2,8),
            Random.ctitle(2,8),
            Random.ctitle(2,8)
          ]
        }
      ],
      pages:Random.integer(1,10),
      total:Random.integer(2,10)
    })
    console.log(tempObj,'/mall4cloud_product/ua/category/category_list')
    let result = [ ...tempObj.categoryList]
    return result
  }
)

// 接口/mall4cloud_product/ua/category/shop_category_list
Mock.mock(
    new RegExp(VITE_API_URL + '/mall4cloud_product/ua/category/shop_category_list' + '.*'),
    'get',
    (options?: object): any => {
      let tempObj = Mock.mock({
        "categories|1-10": [
          {
            "categoryId|+1": [ Random.guid(), Random.guid(), Random.guid() ],
            'name|+1':[ Random.ctitle(2,3), Random.ctitle(2,3), Random.ctitle(2,3) ],
            'imgUrl|+1':[Random.image('200x100', '#FF6600'),Random.image('200x100', '#FF6600'),Random.image('200x100', '#FF6600')],
            'categories|1-10':[
                {
                    'categoryId|+1': [ Random.guid(), Random.guid(), Random.guid(),],
                    'name|+1':[Random.ctitle(2,5), Random.ctitle(2,5), Random.ctitle(2,5)],
                    'imgUrl|+1':[Random.image('200x100', '#FF6600'),Random.image('200x100', '#FF6600'),Random.image('200x100', '#FF6600')],
                    'categories|1-10':[
                        {
                            'categoryId|+1': [ Random.guid(), Random.guid(), Random.guid(),],
                            'name|+1':[Random.ctitle(2,6), Random.ctitle(2,6), Random.ctitle(2,6)],
                            'imgUrl|+1':[Random.image('200x100', '#FF6600'),Random.image('200x100', '#FF6600'),Random.image('200x100', '#FF6600')]
                        }
                    ]
                }
            ]
          }
        ]
      })
      
      console.log(tempObj,'/mall4cloud_product/ua/category/shop_category_list')
      let result = [ ...tempObj.categories ]
      return result
    }
  )

// 接口/mall4cloud_product/a/shop_cart/check_items
Mock.mock(
  new RegExp(VITE_API_URL + '/mall4cloud_product/a/shop_cart/check_items' + '.*'),
  'post',
  (options?: object): any => {
    let tempObj = Mock.mock({
      "categoryList|1-10": [
        {
          "categoryId|+1": [
            Random.guid(),
            Random.guid(),
            Random.guid(),
          ],
          'name|+1':[
            Random.ctitle(2,3),
            Random.ctitle(2,3),
            Random.ctitle(2,4)
          ]
        }
      ],
      pages:Random.integer(1,10),
      total:Random.integer(2,10)
    })
    console.log(tempObj,'/mall4cloud_product/a/shop_cart/check_items')
    let result = [ ...tempObj.categoryList]
    return result
  }
)
